#define die()   __asm__("l1:\n\tjmp l1");

#include    <include/types.h>
#include    <include/stdarg.h>
#include    <include/task.h>
#include    <include/traps.h>
#include    <include/system.h>
#include    <include/io.h>
#include    <mm/memory.h>
#include    <dev/console.h>



char printbuff[1024];

static int printf(const char *fmt, ...)
{
    va_list args;
    int i,j;
    char c[2]={0,0};

    va_start(args, fmt);
    i = vsprintf(printbuff, fmt, args);
    va_end(args);

    for (j = 0; j < i; ++j)
    {
        c[0] = printbuff[j];
        c[1] = 7;
        write_con(c, 1);
    }
    return i;
}

void k_main()
{
    int delay;
    cmos_time time;
    cmos_date date;
    init_mem();
    init_con();
    init_task();
    init_traps();
    sti();
    //die();
    // while(1)
    // {
    //     time.sec =  readcmos(0);
    //     time.min =  readcmos(2);
    //     time.hour=  readcmos(4);
    //     BCD_TO_BIN(time.sec);
    //     BCD_TO_BIN(time.min);
    //     BCD_TO_BIN(time.hour);

    //     date.dayofweek =readcmos(6);
    //     date.day =readcmos(7);
    //     date.month =readcmos(8);
    //     date.year = readcmos(9);
    //     BCD_TO_BIN(date.day);
    //     BCD_TO_BIN(date.month);
    //     BCD_TO_BIN(date.year);
    //     date.year+=2000;
    //     goto_xy(0,24);
    //     printf("%04d-%02d-%02d %d %02d:%02d:%02d ", 
    //         date.year,
    //         date.month,
    //         date.day,
    //         date.dayofweek,
    //         time.hour,
    //         time.min,
    //         time.sec
    //         );
    //     delay = 100000000;
    //     while(delay--) {};
    // }
    
    die();
}

